package com.lin.cloud.disk.controller;

import com.lin.cloud.disk.entity.request.JwtTokenRequest;
import com.lin.cloud.disk.entity.request.LoginRequest;
import com.lin.cloud.disk.manage.IUserManageService;
import com.lin.cloud.disk.common.utils.Result;
import com.lin.cloud.disk.entity.response.LoginResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 登录控制器
 * @author ljc
 * @date 2020/12/11 11:38
 */
@RestController
@RequestMapping(value = "/api")
@Slf4j
@Api(tags = "登录控制器")
public class LoginController {

    @Resource
    private IUserManageService userManageService;


    @PostMapping(value = "/login")
    @ApiOperation(value = "登录",response = LoginResponse.class)
    public Result<LoginResponse> login(@RequestBody @Validated LoginRequest request){
        return Result.success(userManageService.login(request));
    }


    @PostMapping(value = "/logout")
    @ApiOperation(value = "登出")
    public Result logout(@RequestBody @Validated JwtTokenRequest request){
        userManageService.batchDeleteCacheByToken(request);
        return Result.success();
    }
}
